﻿using Windows.UI.Xaml.Controls;
using CalendarWindowsApp.Tools;
using System;
using Windows.Storage;

// The Settings Flyout item template is documented at http://go.microsoft.com/fwlink/?LinkId=273769

namespace CalendarWindowsApp.Controls.Calendar
{
    public sealed partial class CalendarSettingFlyout : SettingsFlyout
    {
        public CalendarSettingFlyout()
        {
            this.InitializeComponent();
            this.Loaded += (s, e) =>
            {
                this.CalendarViewCombo.ItemsSource = Extensions.EnumToDictionary<CalendarViews>();
                this.CalendarViewCombo.DisplayMemberPath = "Value";
            };
        }

        private void OnDefaultViewChanged(object sender, SelectionChangedEventArgs e)
        {
            var localSettings = ApplicationData.Current.LocalSettings;

            if (localSettings.Containers.ContainsKey("SettingsContainer"))
            {
                localSettings.Containers["SettingsContainer"].Values["DefaultView"] = (sender as ComboBox).SelectedIndex;
            }
        }
    }
}